/**
 * Created by codeczx on 2018/3/19.
 */
public class QueueBuffer {
    private boolean valueSet;

    public synchronized void put() {
        try {
            if (valueSet) {
                wait();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        valueSet = true;
        System.out.println("valueSet = "+valueSet);
        notifyAll();
    }

    public synchronized void get() {
        try {
            if (!valueSet) {
                wait();
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        valueSet = false;
        System.out.println("valueSet = "+valueSet);
        notifyAll();
    }

}
